package com.cc.dao.impl;

import com.cc.dao.BaseDao;
import com.cc.dao.MeetingRoomDao;
import com.cc.entity.MeetingRoom;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MeetingRoomImpl extends BaseDao implements MeetingRoomDao {
    @Override
    public List<MeetingRoom> queryAllMeetingRoom() {
        List<MeetingRoom> meetingRooms=new ArrayList<>();
        String sql="select * from meetingroom";
        ResultSet rs =executeQuery(sql,null);
        if(rs!=null){
            try {
                while (rs.next()){
                    MeetingRoom meetingRoom=new MeetingRoom();
                    meetingRoom.setId(rs.getInt("id"));
                    meetingRoom.setName(rs.getString("name"));
                    meetingRoom.setNumber(rs.getInt("number"));
                    meetingRoom.setDept(rs.getString("dept"));
                    meetingRoom.setLocal(rs.getString("local"));
                    meetingRoom.setState(rs.getInt("state"));
                    meetingRooms.add(meetingRoom);
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }finally {
                close(rs);
            }
        }
        return meetingRooms;
    }
}
